package com.matt.repository.course;

import com.matt.domain.course.Course;
import com.matt.domain.course.CourseChild;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2018/11/22
 * *******************************
 */
public interface CourseRepository extends JpaRepository<Course, String>{
    List<Course> findByTypeNameAndTypeAndDeleted(String typeName, Integer type, Boolean deleted);

    List<Course> findByTypeNameAndTypeAndDeletedOrderByCreatedDesc(String typeName, Integer type, Boolean deleted);
    List<Course> findByTypeNameAndTypeAndDeletedAndAreaIdOrderByCreatedDesc(String typeName, Integer type, Boolean deleted,String areaId);
    List<Course> findByTypeAndDeletedAndAreaIdOrderByCreatedDesc(Integer type, Boolean deleted,String areaId);

    List<Course> findByTypeNameAndTypeAndAreaIdAndDeletedOrderByCreatedDesc(String typeName, Integer type, String areaId, Boolean deleted);

//    Course findByTypeAndTypeNameAndName(Integer type, String typeName, String name);
    Course findByTypeAndTypeNameAndWeek(Integer type, String typeName, Integer week);
    Course findTopByTypeAndDeleted(Integer type, Boolean deleted);
    Course findTopByTypeAndAreaIdAndDeleted(Integer type,String areaId,Boolean deleted);

    Course findCourseById(String id);

    Course findByAreaIdAndId(String areaId, String id);

    Course findByTypeAndTypeNameAndNameAndAreaId(Integer type, String typeName, String name, String areaId);

    List<Course> findAllByAreaId(String areaId);

//    @Query(value = "select max(typeCode) from course where type=:type and areaId=:areaId and deleted=0", nativeQuery = true)
//    Long findMaxTypeCode(@Param("type") Integer type,@Param("areaId") String areaId);
}
